﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Diagnostics;

namespace _05_NameScopes.Services
{
    [ServiceContract(Namespace = "http://Demos.SBT.com")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ProcessList
    {
        // Add [WebGet] attribute to use HTTP GET
        [OperationContract]
        public IEnumerable<ProcessData> GetProcesses()
        {
            foreach (var process in Process.GetProcesses())
            {
                
                    yield return new ProcessData
                    {
                        Name = process.ProcessName,
                        Priority = process.BasePriority.ToString(),
                        Memory = process.PrivateMemorySize64,
                        SessionID = process.SessionId
                    };
                
            }
        }

        // Add more operations here and mark them with [OperationContract]
    }

    [DataContract]
    public class ProcessData
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Priority { get; set; }
        [DataMember]
        public int SessionID { get; set; }
        [DataMember]
        public string ProcessTime { get; set; }
        [DataMember]
        public long Memory { get; set; }
    }
}
